<template>
  <div class="carIn">
    <p class="title">车辆入场实时动态 >></p>
    <div class="scrollBox">
      <div id="scroll1">
        <p class="inCar" v-for="(item,index) in carNums" :class="{activeInCar:index%2}">
          <span class="carNum">{{item.carCardNum}}</span><span class="inDate">{{item.inTime}}</span>
        </p>
      </div>
      <div id="scroll2">
        <p class="inCar" v-for="(item,index) in carNums" :class="{activeInCar:index%2}">
          <span class="carNum">{{item.carCardNum}}</span><span class="inDate">{{item.inTime}}</span>
        </p>
      </div>
    </div>
  </div>
</template>
<script>
  import axios from 'axios'
  import qs from 'qs'
  export default {
    name: 'carIn',
    data() {
      return {
        carNums: [],
      }
    },
    mounted() {
      this.getParkIn();
      this.scroll();
    },
    beforeDestroy() {
      if (this.timer) {
        clearInterval(this.timer);
      }
    },
    methods: {
      getParkIn() {
        axios({
          method: 'post',
          url: '/api/cCarInOut/getCarInList',
        }).then((res) => {
          let nums = res.data.data;
          nums.forEach(item => {
            let a = item.carCardNum.split('');
            a.splice(2,3,' * * * ');
            item.carCardNum = a.toString().replace(/,/g, "");
          })
          this.carNums = res.data.data;
        })
      },
      scroll() {
        let len = 0;
        let lenght;
        let height;
        setTimeout(function() {
          height = document.getElementById('scroll1').clientHeight
        },30000)
        this.timer = setInterval(function() {
          len -= 1;
          lenght = len + "px";
          document.getElementById('scroll1').style.marginTop = lenght;
          if(len == -height) {
            len = 0;
          }
        },50)
      },
    }
  }
</script>
<style scoped>
  p {
    margin: 0;
  }
  .title {
    color: #F3F3F3;
    font-family: Adobe Heiti Std R;
    font-size: 1.6rem;
    letter-spacing: 0.12rem;
    position: absolute;
    left: 8.99%;
    top: 4.97%;
  }
  .scrollBox {
    /* border: 1px solid red; */
    width: 77.79%;
    height: 80%;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 6%;
    overflow: hidden;
  }
  .inCar {
    color: #fff;
    padding: 1.2rem;
    font-size: 2rem;
    display: flex;
    justify-content: space-around;
  }
  .activeInCar {
    background-color: rgba(0, 170, 218, 0.5);
  }
  .inDate {
    color: #00FFF6;
  }

</style>
